package me.zhengjie.modules.rest.enterprise;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import me.zhengjie.annotation.AnonymousAccess;
import me.zhengjie.modules.domain.enterprise.EnterpriseAbstract;
import me.zhengjie.modules.service.EnterpriseAbsService;
import me.zhengjie.modules.utils.Contents;
import me.zhengjie.modules.utils.JsonUtils;
import me.zhengjie.modules.utils.ReturnObject;
import org.springframework.web.bind.annotation.*;

@Api("企业简介信息api")
@RestController
@RequiredArgsConstructor
@RequestMapping("/enterAbs")
public class EnterpriseAbsController {

    private final EnterpriseAbsService enterpriseAbsService;

    @AnonymousAccess
    @PostMapping("/EnterAbs/addEnterpriseAbs")
    public @ResponseBody Object addEnterpriseAbs(@RequestBody String json){
        EnterpriseAbstract enterpriseAbstract= JsonUtils.JsonToEnterpriseAbs(json);
        ReturnObject returnObject=new ReturnObject();
        try {
            int num=enterpriseAbsService.addEnterpriseAbs(enterpriseAbstract);
            if(num>0){
                returnObject.setCode(Contents.RETURN_CODE_SUCCESS);
            }else{
                returnObject.setCode(Contents.RETURN_CODE_FAIL);
                returnObject.setMessage(Contents.RETURN_MESSAGE_FAIL);
            }
        }catch (Exception e){
            e.printStackTrace();
            returnObject.setCode(Contents.RETURN_CODE_FAIL);
            returnObject.setMessage(Contents.RETURN_MESSAGE_EXCEPTION);
        }
        return returnObject;
    }

    @AnonymousAccess
    @ApiOperation("根据企业名称获取企业简介信息")
    @GetMapping("/queryEnterpriseAbsByName")
    public EnterpriseAbstract queryEnterpriseAbsByName(String name){
        return enterpriseAbsService.queryEnterpriseAbsByName(name);
    }
}
